package C_Paper;

import java.util.Arrays;

public class C100_15 {
    //分组
    public static void main(String[] args) {
        fs(new int[]{5 ,1, 8, 3, 4, 6, 7, 10, 9, 2});
        fs(new int[]{15 ,1, 18, 3, 14, 6, 7, 10, 9, 2});
    }
    public static void fs(int[] x){
        Arrays.sort(x);
        System.out.println(Arrays.toString(x));
        int a = x[0];
        int b = x[1];
        for (int i = 2; i < x.length; i+=2) {
            if (a > b){
                a+=x[i];
                b+=x[i+1];
            }else {
                b+=x[i];
                a+=x[i+1];
            }
        }
        System.out.println(a+"="+b);
        System.out.println(Math.abs(a-b));
    }
}
